//
//  WeiboAnnotationView.m
//  Project_2_weibo
//
//  Created by 林林 on 16/7/8.
//  Copyright © 2016年 lhn. All rights reserved.
//

#import "WeiboAnnotationView.h"
#import "WeiboAnnoation.h"
#import "UIImageView+WebCache.h"

@implementation WeiboAnnotationView

- (instancetype)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews {
    
    //背景图片
    UIImage *image = [UIImage imageNamed:@"nearby_map_people_bg"];
    UIImageView *bgImageView = [[UIImageView alloc] initWithImage:image];
    //自动调整大小
    [bgImageView sizeToFit];
    [self addSubview:bgImageView];
    
    //调整位置
    bgImageView.center = CGPointZero;
    bgImageView.bottom = 0;
    
    UIImageView *userImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 7, 50, 50)];
    //设置圆角
    userImageView.layer.cornerRadius = 5;
    userImageView.layer.masksToBounds = YES;
    userImageView.backgroundColor = [UIColor clearColor];
    [bgImageView addSubview:userImageView];
    
    //获取标注对象
    WeiboAnnoation *annotion = self.annotation;
    Weibo *weibo = annotion.weibo;
    NSURL *url = [NSURL URLWithString:weibo.user.profile_image_url];
    [userImageView sd_setImageWithURL:url];
}

@end






